package cvn.view.main{

import flash.events.Event;

import mx.resources.ResourceBundle;

public class Localizator{
	
	public static const BRAZIL:int = 1;
	public static const UK:int = 2;
	
    protected static var myLocalizator:Localizator;
	
	[Bindable]
	private var cur:ResourceBundle;
	[ResourceBundle("uk")]
	private var rb_uk:ResourceBundle;
	[ResourceBundle("bra")]
	private var rb_bra:ResourceBundle;
	
	private var _lang:int;

	public function Localizator (language:int=UK){
		selectLang( language );
	}
	
	private function selectLang( language:int ) : void{
		this._lang = language;
		switch ( language ) {
			case UK :
				this.cur = rb_uk;
				break;
			case BRAZIL :
				this.cur = rb_bra;
				break;
			default :
				this._lang = Localizator.UK;
				this.cur = rb_uk;
			break;
		}
	}
	
	public static function getInstance (language:int) : Localizator {
		if( Localizator.myLocalizator == null ){
			Localizator.myLocalizator = new Localizator(language);
		}
		return Localizator.myLocalizator;
	}
	
	[Bindable(event="langChange")]
	public function getText( key:String ) : String {
		return this.cur.getString( key );
	}

	[Bindable(event="langChange")]
	public function gT( key:String ) : String {
		return this.getText(key);
	}
	
	public function get lang () : int {
		return this._lang;
	}
	
	public function set lang ( language:int ) : void {
		if( this._lang != language ){
			this.selectLang( language );
			var e:Event = new Event("langChange");
			this.dispatchEvent(e);
		}
	}
	
}

}